package com.nobody.facepk.pojo;

import java.lang.reflect.Type;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nobody.facepk.pojo.json.Scoring;

public class JsonHelper {
	public static final Type SCORING_TYPE = new TypeToken<List<Scoring>>() {}.getType();
	
	public static <T> List<T> parseAsList(Class<T> clazz, String data){
		Gson gson = new Gson();
		Type dataType = new TypeToken<List<T>>() {}.getType();
		return gson.fromJson(data, dataType);
	}
	
	public static <T> List<T> parseAsList(Type type, String data){
		Gson gson = new Gson();
		return gson.fromJson(data, type);
	}
	
	public static <T> T parse(Class<T> clazz, String data){
		Gson gson = new Gson();
		return gson.fromJson(data, clazz);
	}
	
	public static String toGson(Object data){
		Gson gson = new Gson();
		return gson.toJson(data);
	}
	
}
